//
//  FSwitch.m
//  go5
//
//  Created by 袁飞 on 12-7-22.
//
//

#import "FSwitch.h"
#import "ButtonHandle.h"

@implementation FSwitch

@synthesize ison = ison_;


-(id)initWithOn:(NSString*)on Off:(NSString*)off{
  [super init];
  sprite_on_ = [CCSprite spriteWithSpriteFrameName:on];
  [sprite_on_ retain];
  sprite_off_ = [CCSprite spriteWithSpriteFrameName:off];
  [sprite_off_ retain];
  ison_ = false;
  [self addChild:sprite_off_];
  return self;
}

-(void)onTouchDown:(CGPoint)point{
  ison_ = !ison_;
  if (ison_) {
    [self removeChild:sprite_off_ cleanup:false];
    [self addChild:sprite_on_];
  }else{
    [self removeChild:sprite_on_ cleanup:false];
    [self addChild:sprite_off_];
  }
  [[ButtonHandle sharedButtonHandle] onSwithChange:self];
}

-(CGRect)getControlRect{
  CGRect rect = [sprite_off_ textureRect];
  CGPoint ap = [sprite_off_ anchorPoint];
  float x = -rect.size.width*ap.x;
  float y = -rect.size.height*ap.y;
  //NSLog(@"size %f, %f %f, %f",x, y, rect.size.width, rect.size.height);
  return CGRectMake(x, y, rect.size.width, rect.size.height);
}

@end
